/*
 * @Date: 2024-01-05 08:59:20
 * @LastEditors: lyx
 * @LastEditTime: 2024-01-12 15:17:22
 * @FilePath: \chlor-alkali-cloud-mobile-end\config\index.ts
 * @Description:
 */
const path = require("path");

const config = {
  projectName: "TaroTemplate",
  date: "2024-1-2",
  designWidth: 375,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2,
    375: 2 / 1,
  },
  sourceRoot: "src",
  outputRoot: "dist",
  plugins: ["@tarojs/plugin-html"],
  defineConstants: {},
  copy: {
    patterns: [],
    options: {},
  },
  sass: {
    resource: [
      // path.resolve(__dirname, "..", "src/assets/styles/custom_theme.scss"),
    ],
    // 默认京东 APP 10.0主题 > @import "@nutui/nutui-react-taro/dist/styles/variables.scss";
    data: `@import "@nutui/nutui-react-taro/dist/styles/variables-jmapp.scss";`,
  },
  framework: "react",
  alias: {
    "@/assets": path.resolve(__dirname, "..", "src/assets"),
    "@/pages": path.resolve(__dirname, "..", "src/pages"),
    "@/store": path.resolve(__dirname, "..", "src/store"),
    "@/components": path.resolve(__dirname, "..", "src/components"),
    "@/utils": path.resolve(__dirname, "..", "src/utils"),
    "@/api": path.resolve(__dirname, "..", "src/api"),
    "@/lib": path.resolve(__dirname, "..", "src/lib"),
    "@/i18next": path.resolve(__dirname, "..", "src/i18next"),
  },
  compiler: {
    type: "webpack5",
    prebundle: { enable: false },
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {
          selectorBlackList: ["nut-"],
        },
      },
      url: {
        enable: true,
        config: {
          limit: 1024, // 设定转换尺寸上限
        },
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: "module", // 转换模式，取值为 global/module
          generateScopedName: "[name]__[local]___[hash:base64:5]",
        },
      },
    },
  },
  h5: {
    publicPath: "/",
    staticDirectory: "static",
    // esnextModules: ['nutui-react'],
    postcss: {
      pxtransform: {
        enable: true,
        config: {
          selectorBlackList: ["nut-"],
        },
      },
      autoprefixer: {
        enable: true,
        config: {},
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: "module", // 转换模式，取值为 global/module
          generateScopedName: "[name]__[local]___[hash:base64:5]",
        },
      },
    },
    devServer: {
      proxy: {
        "/open-apis/": {
          target: "https://open.feishu.cn", // 目标服务器地址，API请求将被转发到这里
          changeOrigin: true,
          pathRewrite: {
            "^/open-apis/": "/open-apis/", // 重写路径: 去掉路径中的/api
          },
        },
        "/apis/": {
          target: "http://192.168.182.39:3000", // 目标服务器地址，API请求将被转发到这里
          changeOrigin: true,
          pathRewrite: {
            "^/apis/": "", // 重写路径: 去掉路径中的/api
          },
        },
        "/adapter/": {
          target: "http://chenshoufeng:30000", // 目标服务器地址，API请求将被转发到这里
          changeOrigin: true,
          pathRewrite: {
            "^/adapter/": "", // 重写路径: 去掉路径中的/api
          },
        },
        // 可以配置多个代理规则
      },
    },
  },
};

module.exports = function (merge) {
  if (process.env.NODE_ENV === "development") {
    return merge({}, config, require("./dev"));
  }
  return merge({}, config, require("./prod"));
};
